import request from '@/utils/request'

interface DbConfig {
  dbType: string
  host: string
  port: string
  username: string
  password: string
  dbName: string
}

interface TableInfo {
  tableName: string
  tableComment: string
  columns: ColumnInfo[]
}

interface ColumnInfo {
  columnName: string
  columnType: string
  columnComment: string
  isNullable: string
  isPk: string
}

// 测试数据库连接
export function testConnection(data: DbConfig) {
  return request({
    url: '/tool/gen/db/testConnection',
    method: 'post',
    data
  })
}

// 获取数据库表列表
export function getTableList(params: any) {
  return request({
    url: '/tool/gen/db/list',
    method: 'get',
    params
  })
}

// 获取表结构信息
export function getTableInfo(tableName: string) {
  return request({
    url: '/tool/gen/db/tableInfo',
    method: 'get',
    params: { tableName }
  })
}

// 保存数据库配置
export function saveDbConfig(data: DbConfig) {
  return request({
    url: '/tool/gen/db/config',
    method: 'post',
    data
  })
} 